<template>
  <div>
    <div class="margin20">
      <el-table :data="logisticsList" align="center" style="width: 100%" border
                :row-class-name="tableRowClassName">
        <el-table-column prop="logisticsServiceName" label="运输方式名称" align="center"
                         width="200"></el-table-column>
        <el-table-column prop="transportTime" label="参考运输时效" align="center" width="160"></el-table-column>
        <el-table-column prop="freight" label="预估运费" align="center"></el-table-column>
        <el-table-column prop="warehouseName" align="center" label="仓库名称" width="200"></el-table-column>
        <el-table-column prop="warehouseContacts" align="center" label="收件人" width="160"></el-table-column>
        <el-table-column prop="warehouseAddress" align="center" label="交货地址" min-width="300"></el-table-column>
      </el-table>
    </div>

  </div>
</template>
<script>
import {
  declareProductInfo, logisticsServiceQuery, createOtherWarehouseOrder, queryLogisticsPlan
} from "@/api/order/purchaser"

export default {
  name: 'order-list',
  props: {
    //线上发货物流信息
    logisticsInfo: {},
    //是否打开线上发货物流信息
    isOpenFreightTrial: {
      type: Boolean,
      default: false,
    },
    orderId: {
      type: String / Number,
      default: ""
    },
    // 是否是去发货
    isSendOutGoods: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isOpenLogisticsModal: false,
      programmeForm: [],
      isOpenLogisticsTable: this.isOpenFreightTrial,
      onlineLogisticsInfo: {},//线上发货物流信息
      skuPackageInfo: "",//大包规格信息
      goodsType: "0",//货物类型
      buttonLoading: false,
      proButtonLoading: false,//提交物流方案信息按钮loading
      isShowOrderDetail: false, //是否展示订单详情弹出框
      isOpenOrderDetail: false,
      isShowOnlineLogistics: false,// 是否打开线上物流方案选择弹窗
      logisticsList: [],//物流方案
      warehouseCarrierService: "",// 手填燕文物流方案
      serviceType: "CAINIAO",
    }
  },
  mounted() {
    console.log(this.logisticsInfo)
    this.getTrialList()
  },
  methods: {
    // 自定义表格样式
    tableRowClassName({row, rowIndex}) {
      if (row.logisticsServiceCode == this.logisticsInfo.logisticsServiceCode) {
        return 'warning-row';
      }
    },
    // 获取物流方案
    getLogisticsPlan() {
      if (!this.serviceType) {
        this.$message.error('请选择物流服务商')
        return
      }
      let data = {
        skuPackageInfoList: JSON.stringify(this.onlineLogisticsInfo),
        skuPackageInfo: this.skuPackageInfo,
        sellerLoginId: this.logisticsInfo.sellerLoginId,
        serviceType: this.serviceType
      }

      queryLogisticsPlan(data).then(response => {
        this.$message.info(response.msg)
        // this.logisticsList = response.data
        let list = response.data
        for (let i = 0; i < list.length; i++) {
          this.logisticsList.push({
            freight: list[i].trialResult,
            logisticsServiceCode: list[i].logisticsServiceId,
            logisticsServiceName: list[i].logisticsServiceName,
            transportTime: list[i].logisticsTimeliness,
            warehouseAddress: list[i].deliveryAddress,
            warehouseName: list[i].warehouseName,
          })
        }
      })
    },
    // 获取获取试算物流方案
    getTrialList() {
      // let data = {
      //   "country": this.logisticsInfo.country,
      //   "length": this.skuPackageInfo.goods_length,
      //   "width": this.skuPackageInfo.goods_width,
      //   "height": this.skuPackageInfo.goods_height,
      //   "weight": this.skuPackageInfo.goods_weight,
      //   "type": this.goodsType
      // }
      logisticsServiceQuery(this.logisticsInfo).then(response => {
        // this.$message.info(response.msg)
        this.logisticsList = response.data
      })
    },
    // 确认其他物流发货
    comfirmShipping() {
      this.$confirm("是否确定选择其他物流发货？", '提示').then(() => {
        const params = {
          orderId: this.logisticsInfo.orderId,
          warehouseCarrierService: this.warehouseCarrierService
        }
        createOtherWarehouseOrder(params).then(res => {
          this.$message.success(res.msg);
          this.proButtonLoading = false;
          this.closeOnlineLogistics()
        }).catch(() => {
        })
      })

    },
    // 选择物流方案进行线上发货
    onlineShipment(row) {
      this.$confirm("是否确定选择此物流方案", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.logisticsInfo.logisticsServiceId = row.logisticsServiceId;
        this.logisticsInfo.serviceType = this.serviceType
        declareProductInfo({orderId: this.logisticsInfo.orderId}).then(res => {
          this.programmeForm = res.data;
          if (this.serviceType = "CAINIAO") {
            this.isOpenLogisticsModal = true
          } else (
            this.isOpenLogisticsModal = false
          )
        })
      })
    },
    // 关闭线上发货弹窗
    closeOnlineLogistics() {
      this.isOpenLogisticsTable = false
      this.$emit('logisticsSwitch', false)
    },
  }
}
</script>
<style scoped>
.el-divider__text {
  font-size: 16px;
  font-weight: bold;
  color: #000;
}

.el-table .warning-row {
  background: #ff0000;
}
</style>
